import 'package:flutter/material.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';
import 'package:get/get.dart';

import '../../const/const.dart';

class SettingController extends GetxController {
  RxList<String> footerList = ['Refresh Device List', 'Group Management'].obs;
  RxList<String> footerIcons = [assets.add, assets.refresh].obs;
  RxBool isGroupManager = false.obs;
  void Function()? refreshTable;
  void Function(String)? addGroup;
  void Function()? updateManagerState;
  void Function()? onState;
  @override
  void onInit() {
    super.onInit();
    if (onState != null) {
      onState!();
    }
  }

  void clickFooter(BuildContext context, String v) {
    switch (v) {
      case 'Refresh Device List':
        if (refreshTable != null) {
          refreshTable!();
        }
        break;
      case 'Group Management':
      case assets.refresh:
        isGroupManager.value = !isGroupManager.value;
        if (updateManagerState != null) {
          updateManagerState!();
        }
        break;
      case assets.add:
        var input = TextAlertDialog(
          textStyle: TextStyle(color: Colors.white),
          keyboardType: TextInputType.text,
          inputFormatters: [],
          title: const Text('Add', style: TextStyle(fontSize: 20)),
          sheet: ['Cancel', 'OK'].map(($0) => Text($0)).toList(),
          contentColor: Color(0xFF252934),
          onDone: (p0, p1) {
            if (p0 == 'OK' || p0 == 'Done') {
              if (addGroup != null) {
                addGroup!(p1);
              }
              Navigator.pop(context);
            } else if (p0 == 'Cancel') {
              Navigator.pop(context);
            }
            print('==========> tag = ${p0}, value = ${p1}');
            return true;
          },
        );

        input.show(context);
        break;
      default:
    }
  }
}
